package com.tydic.product.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class ProductCalculateUtils {

    /**
     * 计算税费
     *
     * @param bigDecimal 计算金额
     * @return 税费
     */
    public static BigDecimal calculateTaxation(BigDecimal bigDecimal) {
        return bigDecimal.multiply(new BigDecimal("0.0236")).divide(new BigDecimal("1.0236"), 2, RoundingMode.HALF_UP).stripTrailingZeros();
    }

    /**
     * 计算服务费
     *
     * @param bigDecimal 计算金额
     * @return 服务费
     */
    public static BigDecimal calculateServiceCharge(BigDecimal bigDecimal) {
        return bigDecimal.multiply(new BigDecimal("0.002")).stripTrailingZeros();
    }

    /**
     * 去掉小数点后面多余的0
     *
     * @param bigDecimal
     * @return
     */
    public static String stripTrailingZerosString(BigDecimal bigDecimal) {
        return bigDecimal.stripTrailingZeros().toPlainString();
    }

    /**
     * 去掉小数点后面多余的0
     *
     * @param bigDecimal
     * @return
     */
    public static String stripTrailingZerosString(String bigDecimal) {
        return new BigDecimal(bigDecimal).stripTrailingZeros().toPlainString();
    }

    /**
     * 去掉小数点后面多余的0
     *
     * @param bigDecimal
     * @return
     */
    public static BigDecimal stripTrailingZeros(BigDecimal bigDecimal) {
        return bigDecimal.stripTrailingZeros();
    }
}
